function makeIterator(arr) {
  let nextIterator = 0
  return {
    next: () => {
      if (nextIterator < arr.length) {
        return {
          value: arr[nextIterator++],
          done: false
        }
      } else {
        return {
          done: true
        }
      }
    }
  }
}

const it = makeIterator(['eat', 'sleep', 'run'])
console.log('1', it.next().value)
console.log('2', it.next().value)
console.log('3', it.next().value)
console.log('4', it.next().done)